
#include "GameStateSanitizer.h"

void sanitizeNumPlayers(struct gameState *G) {
	G->numPlayers = floor(Random() * MAX_PLAYERS - 1) + 2;   //between 2 and 4 players
}

void sanitizeCardCounts(struct gameState *G) {
	int n = 0;
	for (n = 0; n < MAX_PLAYERS; n++) {
		G->handCount[n] = floor(Random() * MAX_DECK);
		G->deckCount[n] = floor(Random() * MAX_DECK);
		G->discardCount[n] = floor(Random() * MAX_DECK);
	}
}

void sanitizeCardCountsMore(struct gameState *G) {
	int total = MAX_DECK;
	int n = 0;

	for (n = 0; n < MAX_PLAYERS; n++) {
		G->deckCount[n] = floor(Random() * total);
		total = total - G->deckCount[n];
		G->discardCount[n] = floor(Random() * total);
		total = total - G->discardCount[n];
		G->handCount[n] = floor(Random() * total);
		
		total = MAX_DECK;
	}

}

void sanitizeHandCards(struct gameState *G) {
	int n = 0;
	int c = 0;

	for (n = 0; n < MAX_PLAYERS; n++) {
		for (c = 0; c < MAX_HAND; c++) {
			G->hand[n][c] = floor(Random() * (treasure_map + 1));
		}
	}
}

void sanitizeDeckCards(struct gameState *G) {
	int n = 0;
	int c = 0;

	for (n = 0; n < MAX_PLAYERS; n++) {
		for (c = 0; c < MAX_DECK; c++) {
			G->deck[n][c] = floor(Random() * (treasure_map + 1));
		}
	}
}

void sanitizeDiscardCards(struct gameState *G) {
	int n = 0;
	int c = 0;

	for (n = 0; n < MAX_PLAYERS; n++) {
		for (c = 0; c < MAX_DECK; c++) {
			G->discard[n][c] = floor(Random() * (treasure_map + 1));
		}
	}
}

void generateSaneKingdomCards(int k[10]) {
	int i = 0;
	for (i = 0; i < 10; i++) {
		k[i] = floor(Random() * (treasure_map - adventurer + 1) + gold + 1);
		int j = 0;
		for (j = 0; j < i; j++) {
			if (k[j] == k[i]) {
				i--;  //if two cards are equal try making a random card again.
			}
		}
	}
}

void generateRealisticDeck(struct gameState *G) {
	int i = 0, n = 0;

	for (n = 0; n < MAX_PLAYERS; n++) {
		for (i = 0; i < MAX_DECK; i++) {
			G->hand[n][i] = floor(Random() * (treasure_map + 1));
			G->deck[n][i] = floor(Random() * (treasure_map + 1));
			G->discard[n][i] = floor(Random() * (treasure_map + 1));
		}
	}

}

void getWhoseTurn(struct gameState *G) {
	G->whoseTurn = floor(Random() * G->numPlayers);
}

int generateHandPos(struct gameState *G) {
	int cardsInHand = G->handCount[G->whoseTurn];
	int handpos = floor(Random() * cardsInHand);
	return handpos;
}